const api = "http://localhost:3000"

//新增按钮跳转
function addUser() {
    location.href = './add.html'
}

//删除用户
function delUser(id) {
    if (confirm("确认删除该用户吗？？？")) {
        axios.delete(`${api}/user/${id}`).then(() => {
            location.href = './index.html'
        })
    }
}

//跳转修改页
function editUser(id) {
    location.href = `./up.html?id=${id}`
}

//过滤
function filterUser() {
    render()
}


function render() {
    let keyword = $('#keyword').val()

    axios.get(`${api}/users?keyword=${keyword}`).then((res) => {

        let users = res.data.data
        console.log(res);
        $('tbody').empty()
        users.forEach(item => {
            $('tbody').append(
                `
                <tr>
                        <td>${item.id}</td>
                        <td>${item.uname}</td>
                        <td>${item.uage}</td>
                        <td>
                            <input type="button" value="编辑" onclick="editUser(${item.id})">
                            <input type="button" value="删除" onclick="delUser(${item.id})">
                        </td>
                    </tr>
                `
            )
        });

    })
}

render()